#include<bits/stdc++.h>
#define ld double
using namespace std;
const int N=1e5+100;

int T,n,m,L,V,d[N],v[N],a[N];
int p[N],ps[N],ru[N];
vector<int> pa[N];
int l[N],r[N];
double x;
int y;
int cnt,ans;

void dfs(int k,int sum)
{
    if(k==m+1){ans=min(ans,sum);return ;}
    if(pa[k][0]==0){dfs(k+1,sum);return ;}
    bool flag=true;
    for(int i=1;i<=pa[k][0];i++)
    {
        if(ru[pa[k][i]]<=1){flag=false;break;}
    }
    if(flag)
    {
        for(int i=1;i<=pa[k][0];i++)ru[pa[k][i]]--;
        dfs(k+1,sum);
        for(int i=1;i<=pa[k][0];i++)ru[pa[k][i]]++;
    }
    dfs(k+1,sum+1);
}

int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int i,j;
    cin>>T;
    while(T--)
    {
        cin>>n>>m>>L>>V;
        for(i=0;i<=L;i++)ps[i]=0;
        for(i=0;i<=m;i++)
        {
            pa[i].clear();
            pa[i].push_back(0);
        }
        for(i=1;i<=n;i++)
        {
            ru[i]=0;
            cin>>d[i]>>v[i]>>a[i];
            if(!a[i])
            {
                if(v[i]>V){l[i]=d[i];r[i]=L;}
                else l[i]=r[i]=0;
            }
            else if(a[i]>0)
            {
                if(v[i]==V){l[i]=d[i]+1;r[i]=L;}
                if(v[i]>V){l[i]=d[i];r[i]=L;}
                else
                {
                    x=((ld)(V*V-v[i]*v[i])/(ld)a[i]/(ld)2);
                    y=x+1;
                    if(y>L)l[i]=r[i]=0;
                    l[i]=d[i]+y;r[i]=L;
                }
            }
            else
            {
                if(v[i]<=V)l[i]=r[i]=0;
                else
                {
                    x=((ld)(V*V-v[i]*v[i])/(ld)a[i]/(ld)2);
                    y=x;if(y==x)y--;
                    l[i]=d[i];r[i]=min(d[i]+y,L);
                }
            }
        }
        for(i=1;i<=m;i++)
        {
            cin>>p[i];
            ps[p[i]]=1;
        }
        p[m+1]=L+1;
        for(i=1;i<=L;i++)ps[i]+=ps[i-1];
        cnt=0;
        for(i=1;i<=n;i++)
        {
            if(l[i]==0 and r[i]==0)continue;
            if(l[i]==0)cnt+=(ps[r[i]]!=0);
            else if(ps[r[i]]>ps[l[i]-1])cnt++;
        }
        cout<<cnt<<" ";
        //the close
        for(i=1;i<=n;i++)
        {
            int a1=lower_bound(p+1,p+m+1,l[i])-p;
            int a2=upper_bound(p+1,p+m+2,r[i])-p-1;
            for(j=a1;j<=a2;j++)
            {
                pa[j][0]++;
                pa[j].push_back(i);
                ru[i]++;
            }
        }
        ans=m;
        dfs(1,0);
        cout<<m-ans<<endl;
    }
    return 0;
}
